package com.uhylab.uhuvinetest.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.uhylab.uhuvinetest.R;
import com.uhylab.uhuvinetest.adapter.UHGuideVP_Adapter;
import com.uhylab.uhuvinetest.base.UHBaseActivity;
import com.uhylab.uhuvinetest.utils.sharedpreutils.SharedPreUtils;


/**
 * Created by xyb on 15/12/8 at UHylab
 *
 * @version 1.0
 */
public class UHGuideActivity extends UHBaseActivity implements ViewPager.OnPageChangeListener, View.OnClickListener {
    private ViewPager guide_viewpager;
    private UHGuideVP_Adapter uhGuideVP_adapter;
    private LinearLayout guide_button;
    private ImageView guide_login;
    private ImageView guide_see;

    @Override
    public int bindLayout() {
        return R.layout.activity_guide;
    }

    @Override
    public void initView(View view) {

        guide_viewpager = (ViewPager) view.findViewById(R.id.guide_viewpager);
        guide_button = (LinearLayout) view.findViewById(R.id.guide_button);
        uhGuideVP_adapter = new UHGuideVP_Adapter(getContext());
        guide_viewpager.setAdapter(uhGuideVP_adapter);

        guide_login = (ImageView) findViewById(R.id.guide_login);
        guide_see = (ImageView) findViewById(R.id.guide_see);
    }

    @Override
    public void doBusiness(Context mContext) {
        guide_viewpager.addOnPageChangeListener(this);

        guide_login.setOnClickListener(this);
        guide_see.setOnClickListener(this);

//        guide_button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                SharedPreUtils.setBoolean(getContext(), "is_first_open", true);
//                Intent intent = new Intent(getContext(), UHMainActivity.class);
//                startActivity(intent);
//                finish();
//
//            }
//        });

    }

    @Override
    public void resume() {

    }

    @Override
    public void destroy() {

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        if (position == 2) {
            guide_button.setVisibility(View.VISIBLE);
        } else {
            guide_button.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.guide_see:
                SharedPreUtils.setBoolean(getContext(), "is_first_open", true);
                Intent intent = new Intent(getContext(), UHMainActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.guide_login:
                SharedPreUtils.setBoolean(getContext(), "is_first_open", true);
                Intent intent1 = new Intent(getContext(),UHLogonActivity.class);
                startActivity(intent1);
                finish();
                break;
        }
    }
}
